import mongoose from 'mongoose';
import { ICheck } from '@/types/model';

const CheckSchema = new mongoose.Schema<ICheck>({
    checkId: { type: String, required: true, unique: true },
    title: { type: String, required: true },
    completed: { type: Boolean, default: false },
    completedAt: { type: Number },
    createdAt: { type: Number, default: Date.now },
    updatedAt: { type: Number, default: Date.now },
    checkListId: { type: String, required: true }
}, {
    id: false,
    collection: 'checks',
    toJSON: { 
        getters: true, 
        virtuals: false,
        transform: (doc, ret) => {
            delete ret._id;
            delete ret.__v;
            return ret;
        }
    },
    toObject: { 
        getters: true, 
        virtuals: false,
        transform: (doc, ret) => {
            delete ret._id;
            delete ret.__v;
            return ret;
        }
    }
});

export const Check = mongoose.model<ICheck>('Check', CheckSchema);